#!/usr/bin/env python3
"""Test suite for functions in module ReadNMEA.py"""

# For testing correctness of PYTHONPATH:
# import os
# print(os.getenv('PYTHONPATH'))
# print
# import sys
# print(sys.path)

import unittest
# import numpy.testing as ntp
import ReadNMEA as rn


class NMEA2NM(unittest.TestCase):
    """A series of tests for valid input."""
    def test_known(self):
        """Tests to make sure NMEA2NM works as intended.
        AlmostEgual does not deal with tuples so Lat and Long are
        tested separately.
        The first 16 tests are kind of basic exploration of the algorithm.
        In the last two tests I benchmark against gpsbabel.
        Yes, four decimal places is excessive accuracy for the intended use."""
        self.assertAlmostEqual(rn.NMEA2NM(0.0, 0.0)[0], 0.0, places=4)
        self.assertAlmostEqual(rn.NMEA2NM(0.0, 0.0)[1], 0.0, places=4)
        self.assertAlmostEqual(rn.NMEA2NM(100.0, 0.0)[0], 60.0, places=4)
        self.assertAlmostEqual(rn.NMEA2NM(100.0, 0.0)[1], 0.0, places=4)
        self.assertAlmostEqual(rn.NMEA2NM(0.0, 100.0)[0], 0.0, places=4)
        self.assertAlmostEqual(rn.NMEA2NM(0.0, 100.0)[1], 60.0, places=4)
        self.assertAlmostEqual(rn.NMEA2NM(6000.0, 100.0)[0], 3600.0, places=4)
        self.assertAlmostEqual(rn.NMEA2NM(6000.0, 100.0)[1], 30.0, places=4)
        self.assertAlmostEqual(rn.NMEA2NM(-6000.0, 100.0)[0], -3600.0, places=4)
        self.assertAlmostEqual(rn.NMEA2NM(-6000.0, 100.0)[1], 30.0, places=4)
        self.assertAlmostEqual(rn.NMEA2NM(9000.0, 100.0)[0], 5400.0, places=4)
        self.assertAlmostEqual(rn.NMEA2NM(9000.0, 100.0)[1], 0.0, places=4)
        self.assertAlmostEqual(rn.NMEA2NM(0.0, 30.0)[0], 0.0, places=4)
        self.assertAlmostEqual(rn.NMEA2NM(0.0, 30.0)[1], 30.0, places=4)
        self.assertAlmostEqual(rn.NMEA2NM(5820.0, 0.0)[0], 3500.0, places=4)
        self.assertAlmostEqual(rn.NMEA2NM(5820.0, 0.0)[1], 0.0, places=4)
        self.assertAlmostEqual(rn.NMEA2NM(5915.0093, 1824.4705)[0], 3555.0093, places=4)
        self.assertAlmostEqual(rn.NMEA2NM(5915.0093, 1824.4705)[1], 564.70556, places=4)


if __name__ == '__main__':
    unittest.main()
